﻿using Mes.Domain.BoundedContext.EntityBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mes.Domain.BoundedContext.Entities.Quality
{
    /// <summary>
    /// 质量特征实体
    /// </summary>
    public class Characteristic : NoIdEntityBase
    {
        /// <summary>
        /// 特征名称
        /// Name of characteristic for display
        /// </summary>
        public string Char_Name { get; set; }

        /// <summary>
        /// 特征描述
        /// Description of characteristic
        /// </summary>
        public string? Char_Desc { get; set; }

        /// <summary>
        /// 特征类型
        /// 0 (default) = variable, 1 = binary attribute, 2 = counted attribute
        /// </summary>
        public int Type { get; set; } = 0;

        /// <summary>
        /// 计量单位Id
        /// Identify unit of measure for this characteristic
        /// </summary>
        public int Uom_Id { get; set; }

        /// <summary>
        /// 严重性
        /// 0 = Unused (not available for data entry), 1 = Not Monitored (run rule violations not checked), 2 =  Non-Key (default), 3 = Key, 4 = Critical
        /// </summary>
        public int Severity_Cd { get; set; } = 2;

        /// <summary>
        /// 默认图
        /// 2 = Xbar + Range, 3 = Xbar + Sigma, 5 (default) = IX + MR, 7 = MA + Range, 8 = MA + Sigma, 16 = p, 17 = np, 18 = u, 19 = c, 20 = DPMO (coding per QI Analyst)
        /// </summary>
        public int Default_Chart { get; set; } = 5;

        /// <summary>
        /// 自动收集
        /// Is this characteristic to be collected automatically? Default = no
        /// </summary>
        public bool Automated_Coll { get; set; } = false;

        /// <summary>
        /// 时间间隔
        /// If sample_size > 1 and automated_coll is Yes, the interval between samples.  Note this is a default for the characteristic, which can be overridden independently at each SRO
        /// </summary>
        public int? Time_Interval { get; set; }

        /// <summary>
        /// 时间间隔单位
        /// 0 = seconds, 1 = minutes, 2 = hours
        /// </summary>
        public int? Time_Int_Unit { get; set; }

        /// <summary>
        /// 小数位数
        /// The number of decimals to display. Default = 0
        /// </summary>
        public int Num_Decimals { get; set; } = 0;

        /// <summary>
        /// 样本大小来源
        /// If type = 1 or 2 (attribute)  0 = fixed (default), 1 = entered, 2 = entered but copied from the previous value
        /// </summary>
        public int? Sample_Size_Source { get; set; } = 0;

        /// <summary>
        /// 标准样本大小
        /// If variable or attribute with fixed sample size, the normal number of measurements ina sample; default = 1
        /// </summary>
        public int Normal_Sample_Size { get; set; } = 1;

        /// <summary>
        /// 最小样本大小
        /// The minimum number of measurements in a sample; default = 1
        /// </summary>
        public int Minimum_Sample_Size { get; set; } = 1;

        /// <summary>
        /// 最大样本大小
        /// The maximum number of measurements in a sample
        /// </summary>
        public int? Maximum_Sample_Size { get; set; }

        /// <summary>
        /// 可能产生不良品的数量
        /// If counted attribute, the number of defect opportunities per piece
        /// </summary>
        public int? Num_Defect_Opp { get; set; }

        /// <summary>
        /// 移动平均跨度
        /// Number of subgroups to average for moving average chants
        /// </summary>
        public int? Mov_Avg_Span { get; set; }

        /// <summary>
        /// Sigma估算
        /// If variable, 0 = use tables, 1 = use std. dev.
        /// </summary>
        public int? Sigma_Est { get; set; }

        /// <summary>
        /// 如果变化，趋势x条和IX限制。默认值= yes
        /// If variable, trend x-bar and IX limits.  Default = yes
        /// </summary>
        public bool Trend_Limits { get; set; } = true;

        /// <summary>
        /// 如果趋势限制= yes，则使用回归的标准误差作为西格玛估计。默认=否
        /// If trend limits = yes, use standard error of regression as sigma estimate.  Default = no
        /// </summary>
        public bool Use_Std_Err { get; set; } = false;

        /// <summary>
        /// 极限控制来源
        /// 0 =从数据自动计算(默认)，1 =从标准均值和标准差值计算(如果变量)或从标准p、np的平均比例和标准c、u的平均数量计算单位值(如果属性)，2 =使用预设值
        /// 0 = automatically calculate from data (default), 1 = compute from standard mean and standard deviation values (if variable) or compute from standard p, np average proportion and standard c, u average number per unit values (if attribute), 2 = use preset values
        /// </summary>
        public int? Cl_Source { get; set; } = 0;

        /// <summary>
        /// 控制极限的样本
        /// If cl_source = 0, the number of samples to use for the calculation of control limits. 0 (default) = use all
        /// </summary>
        public int? Samples_For_Cl { get; set; } = 0;

        /// <summary>
        /// 计算控制限制之前所必须的样本
        /// If cl_source = 0, the number of samples required before control limits are calculated; default = 1
        /// </summary>
        public int Samples_Before_Cl { get; set; } = 1;

        /// <summary>
        /// 标准平均值
        /// Only meaningful if cl_source = 1 (may not then be null).  If type is variable this is the standard mean; if a binary attribute this is the standard p, np average proportion value; if a counted attribute this is the standard c, u average number per unit value.
        /// </summary>
        public float? Std_Avg { get; set; }

        /// <summary>
        /// 标准平均值为目标
        /// Only meaningful if cl_source = 1.  If yes (default) use the target instead of the std_avg value as the standard.
        /// </summary>
        public bool Std_Avg_Is_Target { get; set; } = true;

        /// <summary>
        /// 标准偏差
        /// If variable and cl_source = 1, the  standard deviation
        /// </summary>
        public float? Std_Deviation { get; set; }

        /// <summary>
        /// Xbar图中间线
        /// If variable and cl_source = 2, center line for x_bar
        /// </summary>
        public float? Cl_Xbar { get; set; }

        /// <summary>
        /// Xbar图最低控制极值
        /// If variable and cl_source = 2, lower control limit for x_bar
        /// </summary>
        public float? Lcl_Xbar { get; set; }

        /// <summary>
        /// Xbar图最高控制极值
        ///If variable and cl_source = 2, upper control limit for x_bar 
        /// </summary>
        public float? Ucl_Xbar { get; set; }

        /// <summary>
        /// Range图中间线
        /// If variable and cl_source = 2, center line for range
        /// </summary>
        public float? Cl_Range { get; set; }

        /// <summary>
        /// Range图最低控制极值
        /// If variable and cl_source = 2, lower control limit for range
        /// </summary>
        public float? Lcl_Range { get; set; }

        /// <summary>
        /// Range图最高控制极值
        /// If variable and cl_source = 2, upper control limit for range
        /// </summary>
        public float? Ucl_Range { get; set; }

        /// <summary>
        /// Sigma图中间线
        /// If variable and cl_source = 2, center line for sigma
        /// </summary>
        public float? Cl_Sigma { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for sigma
        /// </summary>
        public float? Lcl_Sigma { get; set; }

        /// <summary>
        /// If variable and cl_source = 2, upper control limit for sigma
        /// 图最高控制极值
        /// </summary>
        public float? Ucl_Sigma { get; set; }

        /// <summary>
        /// 图中间线
        /// If variable and cl_source = 2, center line for individual x
        /// </summary>
        public float? Cl_Ix { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for individual x
        /// </summary>
        public float? Lcl_Ix { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If variable and cl_source = 2, upper control limit for individual x
        /// </summary>
        public float? Ucl_Ix { get; set; }

        /// <summary>
        /// 图中间线
        /// If variable and cl_source = 2, center line for individual moving range
        /// </summary>
        public float? Cl_Imr { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for individual moving range
        /// </summary>
        public float? Lcl_Imr { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If variable and cl_source = 2, upper control limit for individual moving range
        /// </summary>
        public float? Ucl_Imr { get; set; }

        /// <summary>
        /// 图中间线
        /// If variable and cl_source = 2, center line for moving average
        /// </summary>
        public float? Cl_Ma { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for moving average
        /// </summary>
        public float? Lcl_Ma { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If variable and cl_source = 2, upper control limit for moving average
        /// </summary>
        public float? Ucl_Ma { get; set; }

        /// <summary>
        /// 图中间线
        /// If variable and cl_source = 2, center line for moving range
        /// </summary>
        public float? Cl_Mr { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for moving range
        /// </summary>
        public float? Lcl_Mr { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If variable and cl_source = 2, upper control limit for moving range
        /// </summary>
        public float? Ucl_Mr { get; set; }

        /// <summary>
        /// 图中间线
        /// If variable and cl_source = 2, center line for moving sigma
        /// </summary>
        public float? Cl_Ms { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If variable and cl_source = 2, lower control limit for moving sigma
        /// </summary>
        public float? Lcl_Ms { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If variable and cl_source = 2, upper control limit for moving sigma
        /// </summary>
        public float? Ucl_Ms { get; set; }

        /// <summary>
        /// 图中间线
        /// If attribute and cl_source = 2, center line for p
        /// </summary>
        public float? Cl_P { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If attribute and cl_source = 2, lower control limit for p
        /// </summary>
        public float? Lcl_P { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If attribute and cl_source = 2, upper control limit for p
        /// </summary>
        public float? Ucl_P { get; set; }

        /// <summary>
        /// 图中间线
        /// If attribute and cl_source = 2, center line for np
        /// </summary>
        public float? Cl_Np { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If attribute and cl_source = 2, lower control limit for np
        /// </summary>
        public float? Lcl_Np { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If attribute and cl_source = 2, upper control limit for np
        /// </summary>
        public float? Ucl_Np { get; set; }

        /// <summary>
        /// 图中间线
        /// If attribute and cl_source = 2, center line for c
        /// </summary>
        public float? Cl_C { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If attribute and cl_source = 2, lower control limit for c
        /// </summary>
        public float? Lcl_C { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If attribute and cl_source = 2, upper control limit for c
        /// </summary>
        public float? Ucl_C { get; set; }

        /// <summary>
        /// 图中间线
        /// If attribute and cl_source = 2, center line for u
        /// </summary>
        public float? Cl_U { get; set; }

        /// <summary>
        /// 图最低控制极值
        /// If attribute and cl_source = 2, lower control limit for u
        /// </summary>
        public float? Lcl_U { get; set; }

        /// <summary>
        /// 图最高控制极值
        /// If attribute and cl_source = 2, upper control limit for u
        /// </summary>
        public float? Ucl_U { get; set; }

        /// <summary>
        /// 如果变量，检验是否适合0 = Shapiro-Wilk, 1 = Kolmogorov-Smirnov, 2 = Chi-Square, 3 = None
        /// If variable, test to use for goodness of fit 0 = Shapiro-Wilk, 1 = Kolmogorov-Smirnov, 2 = Chi-Square, 3 = None
        /// </summary>
        public int? Fit_Test { get; set; }

        /// <summary>
        /// 0 =使用R-Bar的估计，1 =使用S-Bar的估计，2 =使用组内变异
        /// 0 = estimate using R-Bar, 1 = estimage using S-Bar, 2 = use within-group variation
        /// </summary>
        public int? Hist_Capability_Sigma { get; set; }

        /// <summary>
        /// 按实体编号进行筛选
        /// Should default dataset be limited by ent_id of current/last sample even if qm_spec has null ent_id.  Default = no
        /// </summary>
        public bool Filter_By_Ent_Id { get; set; } = false;

        /// <summary>
        /// 按物料编号进行筛选
        /// Should default dataset be limited by item_id of current/last sample even if qm_spec has null item_id, item_class_id, and parent_item_class_id. Default = No
        /// </summary>
        public bool Filter_By_Item_Id { get; set; } = false;

        /// <summary>
        /// 按工单编号进行筛选
        /// Should default dataset be limited by wo_id of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Wo_Id { get; set; } = false;

        /// <summary>
        /// 按操作编号进行筛选
        /// Should default dataset be limited by oper_id of current/last sample even if qm_spec has null oper_id. Default = No
        /// </summary>
        public bool Filter_By_Oper_Id { get; set; } = false;

        /// <summary>
        /// 按生产调度进行筛选
        /// Should default dataset be limited by process_id of current/last sample. Default = No
        /// </summary>
        public bool Filter_By_Process_Id { get; set; } = false;

        /// <summary>
        /// 按段请求编号进行筛选
        /// Should default dataset be limited by segment_req_id of current/last sample. Default = No
        /// </summary>
        public bool Filter_By_Segment_Req_Id { get; set; } = false;

        /// <summary>
        /// 按段响应编号进行筛选
        /// Should default dataset be limited by segment_resp_id of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Segment_Resp_Id { get; set; } = false;

        /// <summary>
        /// 按备用字段1筛选
        /// Should default dataset be limited by the values in the spare1 field of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Spare1 { get; set; } = false;

        /// <summary>
        /// 按备用字段2筛选
        /// Should default dataset be limited by the values in the spare2 field of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Spare2 { get; set; } = false;

        /// <summary>
        /// 按备用字段3筛选
        /// Should default dataset be limited by the values in the spare3 field of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Spare3 { get; set; } = false;

        /// <summary>
        /// 按备用字段4筛选
        /// Should default dataset be limited by the values in the spare4 field of current/last sample.  Default = No
        /// </summary>
        public bool Filter_By_Spare4 { get; set; } = false;

        /// <summary>
        /// 特征备用字段1
        /// Spare field
        /// </summary>
        public string? Spare1 { get; set; }

        /// <summary>
        /// 特征备用字段2
        /// Spare field
        /// </summary>
        public string? Spare2 { get; set; }

        /// <summary>
        /// 特征备用字段3
        /// Spare field
        /// </summary>
        public string? Spare3 { get; set; }

        /// <summary>
        /// 特征备用字段4
        /// Spare field
        /// </summary>
        public string? Spare4 { get; set; }

        /// <summary>
        /// 最新编辑原因
        /// Why record was changed
        /// </summary>
        public string? Last_Edit_Comment { get; set; }

        /// <summary>
        /// 最新编辑用户
        /// Who last changed record
        /// </summary>
        public string Last_Edit_By { get; set; } = String.Empty;

        /// <summary>
        /// 最新编辑时间
        /// When record was last changed
        /// </summary>
        public DateTime Last_Edit_At { get; set; } = DateTime.Now;

        /// <summary>
        /// 特征Id
        /// Unique row identifier, for characteristic.
        /// </summary>
        public int Char_Id { get; set; }
    }
}
